<?php
/**
 * System_Model_StatusMapper
 *
 * @author mmxie
 * @copyright Copyright (c) 2009 Green Shore (http://www.iwgame.com)
 * @version $Id: StatusMapper.php 445 2011-04-25 06:14:40Z mmxie $
 */
class System_Model_StatusMapper extends IG_ModelMapper
{
    /**
     *
     * @param System_Model_Status $model
     */
    public function save($model)
    {
        $oldModel = new System_Model_Status();
        $this->find($model->getStatusKey(), $oldModel);
        $entity = array(
            'val' => $model->getVal()
        );
        if ($oldModel->getVal() != null) {
            $where = array(
                'status_key=?' => $model->getStatusKey(),
                'val<?'=> $model->getVal()
            );
            return $this->getDbTable()->update($entity, $where);
        } else {
            $entity['status_key'] = $model->getStatusKey();
            return $this->getDbTable()->insert($entity);
        }
    }
}